package com.dk.controller;


import com.dk.bean.Result;
import com.dk.em.ResultEnum;
import com.dk.pojo.Content;
import com.dk.service.ContentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张成涛
 * @since 2021-08-12
 */
@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @ApiOperation(value = "广告查询")
    @GetMapping
    public Result toSelect(){
       List<Content> list = contentService.toSelect();
       return Result.buildResult(ResultEnum.SUCCESS).setData(list);
    }
    @ApiOperation(value = "广告增加")
    @PostMapping("toInster")
    public Result toInster(@RequestBody Content content){
        contentService.toInster(content);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
    @ApiOperation(value = "广告修改")
    @PostMapping("toUpdate")
    public Result toUpdate(@RequestBody Content content){
        contentService.toUpdate(content);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
    @ApiOperation(value = "广告删除")
    @DeleteMapping("/{contentId}")
    public Result toDelete(@PathVariable("contentId") Integer contentId){
        contentService.toDelete(contentId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
}

